package com.knowledge.plans;

import com.environment.Order;
import com.knowledge.facts.Condition;
import com.knowledge.facts.FactRepository;
import java.util.HashSet;
import java.util.Set;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author keithballantyne
 */
public abstract class Plan {
    protected Set<Condition> preconditions = new HashSet<Condition>();
    protected Set<Condition> postconditions = new HashSet<Condition>();
    protected Set<Order> movement = new HashSet<Order>();
    
    public Set<Condition> getMissingPreconditions() {
        Set<Condition> preConditions = preconditions;
        
        for (Condition cond: preconditions) {
            if (cond.operator == Condition.Op.ASSERT && FactRepository.getInstance().hasFactClass(cond.factClass)) preConditions.remove(cond);
            else if (cond.operator == Condition.Op.CLEAR && !FactRepository.getInstance().hasFactClass(cond.factClass)) preConditions.remove(cond);
        }
        
        return preConditions;
    }
    
    public Set<Condition> getPreconditions() {
        return preconditions;
    }

    public Set<Condition> getPostconditions() {
        return postconditions;
    }
    
    public abstract void calculateUtility();
}
